﻿using System;
using System.IO;
using System.Linq;
using System.Xml.Linq;

namespace Facade.PageMaker
{
    public class PageMaker
    {
        private PageMaker()
        {
        }

        public static void MakeWelcomePage(string mailAddress, string fileName)
        {
            try
            {
                XElement xml = Database.GetProperties(@"../../MailData.xml");
                string userName = (from r in xml.Elements("property")
                                   where r.Attribute("address").Value == mailAddress
                                   select r.Value).FirstOrDefault();

                HtmlWriter writer = new HtmlWriter(new StreamWriter(fileName));
                writer.Title("Welcome to " + userName + "'s page!");
                writer.Paragraph(userName + "のページへようこそ。");
                writer.Paragraph("メールまっていますね。");
                writer.MailTo(mailAddress, userName);
                writer.Close();
                Console.WriteLine(fileName + " is created for " + mailAddress + " (" + userName + ")");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
    }
}
